<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>更新经济性质数据</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <!--form表单-->
    <!--form表单-->
    <form class="layui-form layui-form-pane ok-form">
        <div class="layui-form-item">
            <label class="layui-form-label">性质代码<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="type_code" id="type_code" placeholder="请输入性质代码，且不重复！" autocomplete="off"
                       class="layui-input"
                       lay-verify="required">
                <input type="text" name="id" id="id" class="layui-input" style="display: none">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性质名称<span style="color: red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="type_name" id="type_name" placeholder="请输入性质名称" autocomplete="off"
                       class="layui-input"
                       lay-verify="required">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态<span style="color: red">*</span></label>
            <div class="layui-input-block" id="LAY-switch-check">
                <input type="checkbox" id="now_status" name="now_status" lay-skin="switch" lay-filter="switchTest"
                       lay-text="启用|停用" checked="">
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea name="remark_describe" id="remark_describe" placeholder="请输入备注内容"
                          class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="edit">立即提交</button>
                <button class="layui-btn layui-btn-primary" id="close">关闭</button>
            </div>
        </div>
    </form>
</div>
</body>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script>
    let data1;

    function child(d) {
        data1 = d
    }

    layui.use(["element", "form", "laydate", "okLayer", "okUtils"], function () {
        let $ = layui.$;
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        okLoading.close();
        console.log(data1);
        $('#id').val(data1.id);
        $('#type_code').val(data1.type_code);
        $('#type_name').val(data1.type_name);
        $('#remark_describe').val(data1.remark_describe);
        $('#now_status').val(data1.now_status);

        if (data1.now_status == 0) {
            layui.jquery('input[name="now_status"]').attr('checked', 'checked');
            layui.jquery('input[name="now_status"]').next().addClass('layui-form-onswitch'); //开
        }
        if (data1.now_status == 1) {
            layui.jquery('input[name="now_status"]').removeAttr('checked');
            layui.jquery('input[name="now_status"]').next().removeClass('layui-form-onswitch'); //关
        }

        // 监听switch状态
        form.on("switch(switchTest)", function (obj) {
            $(obj.elem).attr('type', 'hidden').val(this.checked ? 0 : 1);
        });

        form.on("submit(edit)", function (data) {
            okUtils.ajax("/customer/economic/" + data.field.id, "put", data.field, true).done(function (response) {
                okLayer.greenTickMsg(response.msg, function () {
                    parent.layer.close(parent.layer.getFrameIndex(window.name));
                });
            }).fail(function (error) {
                console.log(error)
            });
            return false;
        });
        $("#close").click(function () {
            let index = parent.layer.getFrameIndex(window.name); //获取当前窗口的name
            parent.layer.close(index);
        });
    })
</script>

</html>
